import { get, post, IList } from "./index";
interface DatasetDetail {
    createTime: string;
    type: string[];
    id: number;
    name: string;
    size: string;
}
// 获取数据集详细信息
export const getDatasetDetail = async (dataSetId: number): Promise<DatasetDetail> => {
    const res = await get("/dataset/detail", { dataSetId });
    return res.data || {};
};

interface DetailQuery {
    dataSetId: number;
    page: number;
    pageSize: number;
    parentId: number;
}
export interface DetailItem {
    id: number;
    size: string;
    name: string;
    updateTime: string;
    type: 1 | 2; // 文件类型，1 文件，2 文件夹
}

type ListRespon = IList<DetailItem> & { filePath: string };
// 获取数据集详情列表
export const getDatasetFiles = async (data: DetailQuery): Promise<ListRespon> => {
    const res = await post("/datasetfile/list", data);
    return {
        list: res.data.dataSetFileListDtoList || [],
        total: res.data.total || 0,
        filePath: res.data.filePath || "",
    };
};

// 删除数据集文件
export const delDatasetFiles = async (data: { dataSetId: number; fileIdList: number[] }) =>
    post("/datasetfile/delete", data);

// 获取数据集下载路径
interface DownlodUrlParam {
    dataSetId: number;
    fileIdList: number[];
}
// 获取下载文件的url
export const getDataDownloadUrl = async (data: DownlodUrlParam): Promise<string> => {
    const res: any = await post("/datasetfile/download", data, {
        responseType: "arraybuffer",
    });
    return res;
};

// 数据集文件夹上传
export const uploadDatasetFileList = async (id: number, files: File[]) => {
    const formData = new FormData();
    formData.append("dataSetId", id + "");
    for (const file of files) {
        formData.append("folder", file);
    }
    const res = await post("/datasetfile/uploadFolder", formData, {
        headers: {
            "Content-Type": "multipart/form-data",
        },
    });
    return res;
};
